package com.leo.controller;

import com.leo.service.UserInfoService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @ClassName: LoggerRecordController
 * @Description: ${description}
 * @Author: leo825
 * @Date: 2020-02-09 18:18
 * @Version: 1.0
 */
@Controller
@RequestMapping("/log")
public class LoggerRecordController {
    //获取日志
    private static final Logger LOGGER = LogManager.getLogger();

    @Autowired
    UserInfoService userInfoService;

    @RequestMapping("/testLog1")
    @ResponseBody
    public ModelAndView testLog1(@RequestParam("username") String name) {
        long startTime = System.currentTimeMillis();
        ModelAndView modelAndView = new ModelAndView();
        //访问数据库
        List userInfoList = userInfoService.getUserInfoList();
        LOGGER.info(userInfoList);
        modelAndView.addObject("data", userInfoList);
        modelAndView.setViewName("success");//跳转到/WEB-INF/views/success.jsp
        LOGGER.info("获取name=" + name + "接口耗时：" + (System.currentTimeMillis() - startTime) + "ms");
        return modelAndView;

    }
}
